package com.lishe.lishe.lishe.utils;

import android.graphics.Rect;
import android.view.TouchDelegate;
import android.view.View;

/**
 * Created by shino on 2017/9/7.
 */

public class ViewUtils {
    /**
     * 加大控件的触摸范围(在原来的基础上加大范围)
     * */
    public static void addTouch(final View view, final int top, final int right,
                          final int bottom, final int left) {
        view.post(new Runnable() {

            @Override
            public void run() {
                Rect rect = new Rect();
                view.getHitRect(rect);
                rect.left += left;
                rect.right += right;
                rect.top += top;
                rect.bottom += bottom;
                TouchDelegate delegate = new TouchDelegate(rect, view);
                if (View.class.isInstance(view.getParent())) {
                    ((View) view.getParent()).setTouchDelegate(delegate);
                }
            }
        });
    }
}
